using Habanero.Testing.Base;
using Microsoft.Practices.Unity;
using NUnit.Framework;
using Rhino.Mocks;

namespace FireStarterModeller.Test
{
    public interface IMyBO
    {
        int GetValue();
    }

    [TestFixture]
    public class TestRhinoExtensions
    {
        [Test]
        public void TestChangeReturn_WhenStub_AndNotClear_ShouldNotReturnNewValue()
        {
            var myBo = MockRepository.GenerateStub<IMyBO>();
            myBo.Stub(bo => bo.GetValue()).Return(1);
            Assert.AreEqual(1, myBo.GetValue());

            myBo.Stub(bo => bo.GetValue()).Return(2);
            Assert.AreNotEqual(2, myBo.GetValue());
        }

        [Test]
        public void TestChangeReturn_WhenStub_AndClear_ShouldReturnNewValue()
        {
            var myBo = MockRepository.GenerateStub<IMyBO>();
            myBo.Stub(bo => bo.GetValue()).Return(1);
            Assert.AreEqual(1, myBo.GetValue());

            myBo.ClearStubReturnValues();

            myBo.Stub(bo => bo.GetValue()).Return(2);
            Assert.AreEqual(2, myBo.GetValue());
        }

        [Test]
        public void TestChangeReturn_WhenMock_AndNotClear_ShouldNotReturnNewValue()
        {
            var myBo = MockRepository.GenerateMock<IMyBO>();
            myBo.Stub(bo => bo.GetValue()).Return(1);
            Assert.AreEqual(1, myBo.GetValue());

            myBo.Stub(bo => bo.GetValue()).Return(2);
            Assert.AreNotEqual(2, myBo.GetValue());
        }

        [Test]
        public void TestChangeReturn_WhenMock_AndClear_ShouldReturnNewValue()
        {
            var myBo = MockRepository.GenerateMock<IMyBO>();
            myBo.Stub(bo => bo.GetValue()).Return(1);
            Assert.AreEqual(1, myBo.GetValue());

            myBo.ClearStubReturnValues();

            myBo.Stub(bo => bo.GetValue()).Return(2);
            Assert.AreEqual(2, myBo.GetValue());
        }
    }
}